import { defineStore } from "pinia";
import { ProcessDefinitionVO } from "@/entiy/vo/ProcessDefinitionVO.ts";
import RequestService from "@/service/RequestService.ts";
import { PageVO } from "@/entiy/vo/PageVO.ts";
import PromiseUtils from "@/utils/PromiseUtils.ts";

export interface FormData {
    pageNum: number,
    pageSize: number,
    deployDate: string,
    deploymentId: string,
    processDefinitionKey: string,
    processDefinitionName: string,
    active: boolean,
}

export const useProcessDefinitionComponentStore = defineStore('processDefinitionComponent', {
    state: () => {
        return {
            // 搜索表单
            formData: {} as FormData,

            // 表格数据
            tableLoading: false,
            tableDataList: [] as Array<ProcessDefinitionVO>,

            // 分页信息
            pageNum: 1,
            pageSize: 10,
            totalRow: 0,
        }
    },

    getters: {},

    actions: {
        async queryTableDataList(): Promise<void> {
            this.formData.pageNum = this.pageNum;
            this.formData.pageSize = this.pageSize;

            const result = await RequestService.post<PageVO<ProcessDefinitionVO>>("/test/query-deployed-process-definition-list", this.formData);
            if (result.isError) {
                return PromiseUtils.reject(result.errorMsg);
            }

            this.totalRow = result.bizDta.totalRow;
            this.tableDataList = result.bizDta.recordList;
        }
    }
})
